{extend name="$base" /}
{block name="resources"}
<link rel="stylesheet" href="WAP_CSS/pay/get_pay_value.css"/>
{/block}
{block name="main"}
{php}
$pay_config = api("System.Pay.getPayConfig");// 支付方式配置
$pay_config = $pay_config['data'];
{/php}

<div class="pay-password-bg" style="display: none" onclick="closePayPassword()"></div>

<div class="pay-pass-bg-wrapper"  style="display: none" >
	<div class="password-div">
		<div class="pay-password-top">
			请输入支付密码
		</div>
		<div class="password-input-wrapper">
			<label for="password" class="password-lable">
				<ul>
					<li></li>
					<li></li>
					<li></li>
					<li></li>
					<li></li>
					<li></li>
				</ul>
				<input id="password" type="password" name="password" maxlength="6">
			</label>
		</div>
	</div>
</div>


<div class="head-info">
	<div class="head-pay">支付金额</div>
	<div class="head-pay-value">￥{$pay_value.pay_money}</div>
</div>

{notempty name="pay_config"}
<div class="pay-type-item">
	<div class="codes">
		{foreach name="$pay_config" item="pay_item"}
		{if $pay_item.is_use}
		<div class="pay-type" {if ($pay_item.addon_name eq 'NsAlipay') and ($supplier_id eq 2) } style="display:none"{/if}  {if ($pay_item.addon_name eq 'NsWeixinpay') and ($supplier_id eq 2) } style="display:none"{/if}   {if ($pay_item.addon_name eq 'NsWeixinpay') or ($recharge eq 0)} {else/} style="display:none"{/if}  data-name="{:lang($pay_item.lang)}"  data-url="{:__URL($pay_item['pay_url'], 'type='. $pay_item['addon_name'].'&no='.$pay_value['out_trade_no'])}">
		<img src="WAP_IMG/pay/{$pay_item.h5_icon}" class="wchat-photo">
		<span class="pay-title">{:lang($pay_item.lang)}</span>
		<span class="pay-check"><img src="WAP_IMG/pay/hgou.png"></span>
	</div>
	{else/}
	{php}$un_num += 1;{/php}
	{/if}
	{/foreach}
	{else/}
	<div class="not-pay-type">商家未配置支付方式</div>
	<input type="hidden" id="out_trade_no" value="{$pay_value.out_trade_no}">
</div>
</div>
{/notempty}

{notempty name="pay_config"}
{if $un_num eq count($pay_config)}
<div class="pay-type-item">
	<div class="codes">
		<div class="not-pay-type">商家未配置支付方式</div>
	</div>
</div>
{else/}
<section class="s-btn">
	<a class="commonpay btn primary"  onclick="showPayPassword()">{:lang('confirm_payment')}</a>
</section>
{/if}
{/notempty}

<script>

	$(".password-div input").on("input",function(e){ //标签为password-div下的input添加oninput事件
		var number = 6;   //定义输入最大值
		var pw = $("input[name = 'password']").val(); //定义pw为name是password的input框的输入值
		var list = $(".password-div ul li");  //定义list是li
		//console.log(pw);
		for(var i = 0; i < number ; i++){    //for循环遍历将·放入li标签
			if(pw[i]){
				$(list[i]).text("·");
			}else{
				$(list[i]).text("");
			};
		};
		if(pw.length == 6){
			calculate(pw);
		}
	});


	$(".password-div ul").click(function(){
		$("input[name = 'password']").val("");
		$("#password").focus();
		$(".password-div ul li").text("");
	});

	function closePayPassword(){

		$(".pay-password-bg").hide()
		$(".pay-pass-bg-wrapper").hide()

	}
	function showPayPassword(){
		var pay_name = $('.pay-type.active').attr('data-name');
		if (pay_name == '微信支付') {
			calculate(pay_name);
		}else{
			if (pay_name == '支付宝支付') {
				calculate(pay_name);}
			else{
				$(".pay-password-bg").show()
				$(".pay-pass-bg-wrapper").show()
			}
		}
	}


	$(function(){
		$('.pay-type:eq(2)').addClass('active');
		$('.pay-type:eq(2) .pay-check').html("<img src='" + WAPIMG + "/pay/segou.png'>");
	});

	var is_sub = false;
	function calculate(pw) {
		if(is_sub) return;
		is_sub = true;
		var pay_url = $('.pay-type.active').attr('data-url');
		if (pay_url != undefined) {
			//微信支付
			var params = {pay_password: pw};
			if(pw === '微信支付'){
				window.location.href = pay_url;
				return;
			}
			if(pw === '支付宝支付'){
				window.location.href = pay_url;
				return;
			}
			api("System.Member.checkPayPassword", params, function (res) {
				console.log(res);
				if(res['data'] === 1){
					window.location.href = pay_url;
				}else{
					toast("{:lang('member_pay_password_error')}");
					is_sub = false;
				}
			})
			//window.location.href = pay_url;
		}else{
			toast("{:lang('choose_payment_method')}");
		}
	}

	$(".alipay").click(function(){
		window.webkit.messageHandlers.calculate.postMessage(null);
	});

	$('.pay-type').click(function(){
		$(this).addClass('active').siblings('.pay-type').removeClass('active');
		$(this).find('.pay-check').html("<img src='" + WAPIMG + "/pay/segou.png'>");
		$(this).siblings('.pay-type').find('.pay-check').html("<img src='" + WAPIMG + "/pay/hgou.png'>");
	});
</script>
{/block}
{block name="footer"}{/block}
